package cn.oppexecise;

import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.OutputStream;

/**
 * @author SWJ
 * @create 2021-06-17 15:13
 * 本类测试字节输出流
 */
public class TestOutputStream {
    public static void main(String[] args) {
        method();//高效输出
//        method2();//普通输出
    }

    private static void method2() {
//高效输出
        OutputStream out = null;
        try {
            out = new BufferedOutputStream
                    (new FileOutputStream("D:\\read\\1.txt"));
            //2使用流对象//2.开始写出数据
            out.write(97);
            //ascii码表存在对应关系:97
            out.write(98);
            out.write(99);
            //在txt中输出abc

        } catch (Exception e) {
            e.printStackTrace();

        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
    }

    private static void method() {
        //普通输出
        OutputStream out = null;
        try {
            out = new FileOutputStream("D:\\read\\1.txt");
            //2使用流对象//2.开始写出数据
            out.write(97);
            //ascii码表存在对应关系:97
            out.write(98);
            out.write(99);
            //在txt中输出abc

        } catch (Exception e) {

        } finally {
            try {
                out.close();
            } catch (IOException e) {
                e.printStackTrace();
            }
        }

    }
}
